import {
  components,
  getComponentMarkdown,
  getComponentAttrMarkdown,
} from './utils'

export async function hoverComponentMarkdown(tag, lc, co) {
  let comp = await getComponent(tag, lc, co)
  return comp ? getComponentMarkdown(comp) : undefined
}

export async function hoverComponentAttrMarkdown(tag, lc, co) {
  let comp = await getComponent(tag, lc, co)
  if (!comp) return
  let attrs = comp.attrs || []
  let attr = undefined
  attrs.find((a) => {
    if (a.name === name) {
      attr = a
    } else if (a.subAttrs) {
      a.subAttrs.some((s) =>
        s.attrs.some((sa) => {
          if (sa.name === name) {
            attr = a
          }
          return !!attr
        })
      )
    }
    return !!attr
  })
  return attr ? getComponentAttrMarkdown(attr) : undefined
}

async function getComponent(tag, lc, co) {
  let comp = [...components].find((c) => c.name === tagName)
  return comp
}
